home *** CD-ROM | disk | FTP | other *** search
- /*
- Generic Queue Management Code
- Steve Falkenburg, MacDTS, Apple Computer
- 3/11/92
-
- */
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #include "const.h"
- #include "globals.h"
- #include "utils.h"
- #include "queues.h"
-
- static QHdr gFreeQueue,gCompletedQueue; // our queue header structures
- static MyQElem gBufferPool[kNumQBuffers]; // queue storage area is here
- static long gFree,gRunning,gCompleted,gServiced; // queue stats
-
- /* initializes our queue handling scheme */
-
- void InitQueues(void)
- {
- short i;
-
- gFreeQueue.qFlags = 0;
- gFreeQueue.qHead = 0;
- gFreeQueue.qTail = 0;
-
- gCompletedQueue.qFlags = 0;
- gCompletedQueue.qHead = 0;
- gCompletedQueue.qTail = 0;
-
- gFree = kNumQBuffers;
- gRunning = gCompleted = 0;
- gServiced = 0;
-
- for (i=0; i<kNumQBuffers; i++)
- Enqueue((QElemPtr)&gBufferPool[i],&gFreeQueue);
- }
-
-
- /* pulls a parameter block off of the unused queue to be used in a device manager call
- */
-
- MyQElemPtr GetUnusedQBlock(void)
- {
- MyQElemPtr retValue;
-
- retValue = (MyQElemPtr) gFreeQueue.qHead;
- if (retValue) {
- Dequeue((QElemPtr)retValue,&gFreeQueue);
- gFree--;
- }
-
- return retValue;
- }
-
-
- /* puts a parameter block back onto the unused queue to be picked up and used by someone else
- */
-
- void RecycleFreeQBlock(MyQElemPtr qBlock)
- {
- Enqueue((QElemPtr)qBlock,&gFreeQueue);
- gFree++;
- }
-
-
- /* pulls a parameter block off of the completed queue for processing by the caller
- */
-
- MyQElemPtr GetCompletedQBlock(void)
- {
- MyQElemPtr retValue;
-
- retValue = (MyQElemPtr) gCompletedQueue.qHead;
- if (retValue) {
- Dequeue((QElemPtr)retValue,&gCompletedQueue);
- gCompleted--;
- }
-
- return retValue;
- }
-
-
- /* queues a parameter block onto the completed queue. this is normally called from completion
- routines at interrupt time.
- */
-
- void StoreCompletedQBlock(MyQElemPtr qBlock)
- {
- Enqueue((QElemPtr)qBlock,&gCompletedQueue);
- gCompleted++;
- }
-